import "package:flutter/material.dart";
import "package:myapp/_common/Tag.dart";

class HotRecommendVideoItemUp {
  String name; //up 名称
  String uid; //up id
  String avatar; //up 头像,
  bool isSubcribed; //是否已关注
  bool isShowUserTag; //是否显示用户标签
  String userTag; //用户标签
  HotRecommendVideoItemUp({
    required this.name,
    required this.uid,
    required this.avatar,
    required this.isSubcribed,
    this.isShowUserTag = false,
    this.userTag = '',
  });
}

// 热门视频
class HotRecommendVideoItem {
  String cover; //视频封面
  String duration; //视频时长
  String title; //视频标题
  String playCount; //播放次数
  bool showSubscribeBar; //是否显示该视频up的关注栏
  HotRecommendVideoItemUp up; //发布视频up
  bool showLikeTag; //是否显示高赞标签
  String likeCount; //最近点赞次数
  bool showShareTag; //是否显示高分享标签
  String shareCount; //最近分享次数
  bool isHot; //是否热门
  String hotTag; //热门标签内容
  String publishTime; //发布时间
  HotRecommendVideoItem({
    required this.cover,
    required this.duration,
    required this.title,
    required this.playCount,
    this.showSubscribeBar = false,
    required this.up,
    this.showLikeTag = false,
    this.likeCount = '',
    this.showShareTag = false,
    this.shareCount = '',
    this.isHot = false,
    this.hotTag = '',
    required this.publishTime,
  });
}

// ignore: must_be_immutable
class HotRecommend extends StatelessWidget {
  List<HotRecommendVideoItem> hotRecommendVideoList = [
    HotRecommendVideoItem(
      cover: './images/1.jpg',
      duration: '3:14',
      title: 'KDA宇智波男团',
      playCount: '37.3万',
      showShareTag: true,
      shareCount: '1万',
      publishTime: '2天前',
      up: HotRecommendVideoItemUp(
        name: 'h-蝎酱',
        uid: '1',
        avatar: "./images/tab_1.jpg",
        isSubcribed: false,
      ),
    ),
    HotRecommendVideoItem(
      cover: './images/2.jpg',
      duration: '0:47',
      title: '第一支视频求三连！',
      playCount: '78.2万',
      showLikeTag: true,
      likeCount: '16万',
      publishTime: '7月10日',
      up: HotRecommendVideoItemUp(
        name: 'bili_43184714',
        uid: '2',
        avatar: "./images/tab_2.jpg",
        isSubcribed: false,
      ),
    ),
    HotRecommendVideoItem(
      cover: './images/3.jpg',
      duration: '4:32',
      title: '《不时用天津话大喊大叫遮羞的散人同学》',
      playCount: '11.2万',
      isHot: true,
      hotTag: '鬼畜剧场·人气飙升',
      publishTime: '21小时前',
      up: HotRecommendVideoItemUp(
        name: 'Ximenbao',
        uid: '3',
        avatar: "./images/tab_3.jpg",
        isSubcribed: false,
      ),
    ),
    HotRecommendVideoItem(
      cover: './images/1.jpg',
      duration: '46:58',
      title: '【纪录片】 大自然的女王 05 海岸女王',
      playCount: '29.7万',
      publishTime: '3小时前',
      up: HotRecommendVideoItemUp(
        name: '哔哩哔哩纪录片',
        uid: '4',
        avatar: "./images/tab_4.jpg",
        isSubcribed: false,
      ),
    ),
    HotRecommendVideoItem(
      cover: './images/2.jpg',
      duration: '2:52',
      title: '广西人的农村生活，今天吃酿菜。',
      playCount: '5.8万',
      publishTime: '7月11日',
      up: HotRecommendVideoItemUp(
        name: '黄大姐-边城妈妈',
        uid: '5',
        avatar: "./images/tab_5.jpg",
        isSubcribed: false,
        userTag: '广西朴实生活日常',
      ),
      showSubscribeBar: true,
    ),
  ];

  HotRecommend({super.key});
  @override
  Widget build(BuildContext context) {
    return SliverList.builder(
      itemCount: hotRecommendVideoList.length,
      itemBuilder: (BuildContext buildContext, int index) {
        return HotRecommendItem(
          hotRecommendVideoItem: hotRecommendVideoList[index],
        );
      },
    );
  }
}

// ignore: must_be_immutable
class HotRecommendItem extends StatelessWidget {
  HotRecommendVideoItem hotRecommendVideoItem;
  HotRecommendItem({
    super.key,
    required this.hotRecommendVideoItem,
  });
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(left: 10),
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      child: Container(
        padding: const EdgeInsets.fromLTRB(0, 10, 8, 10),
        decoration: const BoxDecoration(
          border: Border(
            top: BorderSide(
              width: 0.5,
              color: Colors.black12,
            ),
          ),
        ),
        width: double.infinity,
        child: Column(
          children: [
            hotRecommendVideoItem.showSubscribeBar
                ? Container(
                    margin: const EdgeInsets.only(bottom: 10),
                    child: Row(
                      children: [
                        Expanded(
                          child: Row(
                            children: [
                              Container(
                                margin: const EdgeInsets.only(right: 10),
                                child: CircleAvatar(
                                  backgroundImage: AssetImage(
                                      hotRecommendVideoItem.up.avatar),
                                  radius: 18,
                                ),
                              ),
                              Expanded(
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(hotRecommendVideoItem.up.name),
                                    Tag(hotRecommendVideoItem.up.userTag),
                                  ],
                                ),
                              )
                            ],
                          ),
                        ),
                        Container(
                          padding: const EdgeInsets.only(
                              left: 10, right: 10, top: 1, bottom: 1),
                          decoration: BoxDecoration(
                            border: Border.all(width: 1, color: Colors.pink),
                            borderRadius: BorderRadius.circular(2),
                          ),
                          child: const Row(
                            children: [
                              Icon(
                                Icons.add,
                                size: 16,
                                color: Colors.pink,
                              ),
                              Text(
                                '关注',
                                style: TextStyle(
                                  color: Colors.pink,
                                  fontSize: 13,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  )
                : const SizedBox.shrink(),
            SizedBox(
              width: double.infinity,
              height: 94,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  Padding(
                      padding: const EdgeInsets.only(right: 10),
                      child: SizedBox(
                        width: 160,
                        height: 90,
                        child: ClipRRect(
                          borderRadius: const BorderRadius.all(
                            Radius.circular(4),
                          ),
                          child: Image.asset(
                            hotRecommendVideoItem.cover,
                            width: double.infinity,
                            height: double.infinity,
                            fit: BoxFit.cover,
                          ),
                        ),
                      )),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        SizedBox(
                          height: 42,
                          child: Text(
                            hotRecommendVideoItem.title,
                            maxLines: 2,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                        hotRecommendVideoItem.showLikeTag
                            ? Tag('${hotRecommendVideoItem.likeCount}点赞')
                            : const SizedBox.shrink(),
                        hotRecommendVideoItem.showShareTag
                            ? Tag('${hotRecommendVideoItem.shareCount}分享')
                            : const SizedBox.shrink(),
                        hotRecommendVideoItem.isHot
                            ? Tag(
                                hotRecommendVideoItem.hotTag,
                                plain: true,
                              )
                            : const SizedBox.shrink(),
                        // Text(hotRecommendVideoItem.hotTag),
                        (hotRecommendVideoItem.showLikeTag ||
                                hotRecommendVideoItem.showShareTag ||
                                hotRecommendVideoItem.isHot)
                            ? const SizedBox.shrink()
                            : const SizedBox(height: 14),
                        Row(
                          children: [
                            const Padding(
                              padding: EdgeInsets.only(right: 2),
                              child: Icon(
                                Icons.arrow_drop_down_circle_outlined,
                                size: 14,
                                color: Colors.black45,
                              ),
                            ),
                            Expanded(
                              child: Text(
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                hotRecommendVideoItem.up.name,
                                style: const TextStyle(
                                  color: Colors.black45,
                                  fontSize: 12,
                                ),
                              ),
                            )
                          ],
                        ),
                        Row(
                          children: [
                            const Padding(
                              padding: EdgeInsets.only(right: 2),
                              child: Icon(
                                Icons.ondemand_video_sharp,
                                size: 14,
                                color: Colors.black45,
                              ),
                            ),
                            Expanded(
                              child: Text(
                                maxLines: 1,
                                overflow: TextOverflow.ellipsis,
                                '${hotRecommendVideoItem.playCount}观看·${hotRecommendVideoItem.publishTime}',
                                style: const TextStyle(
                                  color: Colors.black45,
                                  fontSize: 12,
                                ),
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                  const Column(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Icon(
                        Icons.more_vert_outlined,
                        size: 14,
                        color: Colors.black45,
                      )
                    ],
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
